﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Web.Script.Serialization;
using Easy.BLL;
using Easy.Operation;

namespace Easy.Web.Service.Privilege
{
    /// <summary>
    /// UpdateRole 的摘要说明
    /// </summary>
    public class UpdateRole : BaseHttpHandler
    {

        public override void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

           // string json_role = context.Request["role"];
            string json_id = context.Request["RoleId"];
            string json_RolePrivilege = context.Request["RolePrivilege"];
            string json_SiteMap = context.Request["SiteMap"];
            string json_type = context.Request["ShowType"];
            ResultClass rc = new ResultClass();
            try
            {
                JavaScriptSerializer jss = new JavaScriptSerializer();

                 //RoleClass role = jss.Deserialize<RoleClass>(json_role);
                //UserPrivilege_Functions.Role_Save(role, "2", CurrentUserId.ToString());
                if (int.Parse(json_type) == 1)
                {
                    RolePrivilegeClass ur = jss.Deserialize<RolePrivilegeClass>(json_RolePrivilege);
                    UserPrivilege_Functions.RolePrivilege_Save(ur, CurrentUserId.ToString());
                }
                else
                {
                    List<SiteMapClass> SiteMap = jss.Deserialize<List<SiteMapClass>>(json_SiteMap);
                    Guid su = Guid.Parse(json_id);
                    UserPrivilege_Functions.SiteMapId_Save(su, SiteMap, CurrentUserId.ToString());
                }                           

                rc.Result = 0;
                rc.Remark = "";

            }

            catch (Exception e)
            {
                rc.Result = 1;
                rc.Remark = e.Message;
            }


            context.Response.Write(rc.ToJson());
        }

    }
}